package com.springcloud.demo;

/**
 * 策略模式 Demo
 * @Author: linjinp
 * @Date: 2021/1/11 11:43
 */
public class StrategyDemo {

    public final static String EMAIL = "EMAIL";
    public final static String PHONE = "PHONE";

    public void strategy(String param, String model) {
        switch (model) {
            case EMAIL:
                StrategyInterface email = new Email();
                email.strategy(param);
                break;
            case PHONE:
                StrategyInterface phone = new Phone();
                phone.strategy(param);
                break;
        }
    }

    public static void main(String[] args) {
        // 邮件策略方式通知
        new StrategyDemo().strategy("正在发送邮件", StrategyDemo.EMAIL);
        // 电话策略方式通知
        new StrategyDemo().strategy("正在拨打电话", StrategyDemo.PHONE);
    }
}

interface StrategyInterface{
    void strategy(String param);
}

class Email implements StrategyInterface{

    @Override
    public void strategy(String param) {
        System.out.println("邮件方式通信：" + param);
    }
}

class Phone implements StrategyInterface{

    @Override
    public void strategy(String param) {
        System.out.println("电话方式通信：" + param);
    }
}